package modul4;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

/*class awall extends JFrame{
	Container cc = this .getContentPane();
	private JPanel panelAtass = new JPanel();
	
	public awall(){
		inisialisasii();
	}
	
	public void inisialisasii(){
		setLayout(null);
		add(panelAtass);
		
		panelAtass.setBounds(10,20,1105,100);
		panelAtass.setBackground(Color.GREEN);
		
		cc.setBackground(Color.WHITE);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(1140,590);
		setLocation(200,50);
		setTitle("Lihat");
        show();
	}
}*/

public class awal extends JFrame implements ActionListener, ItemListener{
	warung wr = new warung();
	private JPanel panelAtas = new JPanel();
	private JPanel panelBawah = new JPanel();
	private JPanel panelPesan = new JPanel();
	private JPanel panelMenu = new JPanel();
	private JPanel panelMenuu = new JPanel();
	private JPanel panelTombol = new JPanel();
	ImageIcon menu = new ImageIcon("ngilerr.jpg");
	private JLabel lbMenu = new JLabel(menu);
	
	Container c = this .getContentPane();
	private JButton btPesan = new JButton("PESAN");
	private JButton btHitung = new JButton("HITUNG");
	//private JButton btLihat = new JButton("LIHAT");
	private JButton tombol = new JButton("BARU");
	
	private JLabel lbMinum = new JLabel("Menu Minuman");
	private JLabel lbMakan = new JLabel("Menu Makanan");
	private JLabel lbHMinum = new JLabel("Harga Minuman");
	private JLabel lbHMakan = new JLabel("Harga Makanan");
	private JLabel lbJumlah = new JLabel("Jumlah atau Porsi");
	private JLabel lbJumlahh = new JLabel("Jumlah atau Porsi");
	private JLabel lbHarga = new JLabel("Harga");
	private JLabel lbHargaa = new JLabel("Harga");
	private JLabel lbTotal = new JLabel("Total Harga");
	
	private JCheckBox teh = new JCheckBox("Es Teh");
	private JCheckBox jeruk = new JCheckBox("Es Jeruk");
	private JCheckBox soda = new JCheckBox("Susu Soda");
	private JCheckBox joshua = new JCheckBox("Es Joshua");
	private JCheckBox goreng = new JCheckBox("Nasi Goreng");
	private JCheckBox rawon = new JCheckBox("Nasi Rawon");
	private JCheckBox pecel = new JCheckBox("Nasi Pecel");
	private JCheckBox ayam = new JCheckBox("Nasi Ayam");
	private JCheckBox bebek = new JCheckBox("Nasi Bebek");
	private JCheckBox mie = new JCheckBox("Mie Goreng");
	
	private JLabel rp1 = new JLabel();
	private JLabel rp2 = new JLabel();
	private JLabel rp3 = new JLabel();
	private JLabel rp4 = new JLabel();
	private JLabel rp5 = new JLabel();
	private JLabel rp6 = new JLabel();
	private JLabel rp7 = new JLabel();
	private JLabel rp8 = new JLabel();
	private JLabel rp9 = new JLabel();
	private JLabel rp10 = new JLabel();
	
	private JTextField tfJml1 = new JTextField("0");
	private JTextField tfJml2 = new JTextField("0");
	private JTextField tfJml3 = new JTextField("0");
	private JTextField tfJml4 = new JTextField("0");
	private JTextField tfJml5 = new JTextField("0");
	private JTextField tfJml6 = new JTextField("0");
	private JTextField tfJml7 = new JTextField("0");
	private JTextField tfJml8 = new JTextField("0");
	private JTextField tfJml9 = new JTextField("0");
	private JTextField tfJml10 = new JTextField("0");

	private JTextField tfHrg1 = new JTextField("0");
	private JTextField tfHrg2 = new JTextField("0");
	private JTextField tfHrg3 = new JTextField("0");
	private JTextField tfHrg4 = new JTextField("0");
	private JTextField tfHrg5 = new JTextField("0");
	private JTextField tfHrg6 = new JTextField("0");
	private JTextField tfHrg7 = new JTextField("0");
	private JTextField tfHrg8 = new JTextField("0");
	private JTextField tfHrg9 = new JTextField("0");
	private JTextField tfHrg10 = new JTextField("0");
	
	private JTextField tfTotal = new JTextField("0");
	
	public awal(){
		inisialisasi();
	}
	
	public void inisialisasi(){
		setLayout(null);
		add(panelAtas);
		add(lbMenu);
		add(panelBawah);
		
		panelAtas.setBounds(10,20,1105,100);
		panelAtas.setBackground(Color.GREEN);
		
		lbMenu.setBounds(40,130,1045,120);
		
		panelBawah.setBounds(10,260,1105,285);
		panelBawah.setBackground(Color.BLUE);
		panelBawah.setLayout(null);
			panelBawah.add(panelPesan);
			panelPesan.setBackground(Color.YELLOW);
			panelPesan.setBounds(10,10,1085,265);
			panelPesan.setLayout(null);
			//minuman
				panelPesan.add(panelMenu);
				panelMenu.setBackground(new Color(0,150,255));
				panelMenu.setBounds(10,10,530,170);
				panelMenu.setLayout(null);
					Font miring = new Font("Verdana", Font.ITALIC, 12);
					panelMenu.add(lbMinum);
					panelMenu.add(teh);
					panelMenu.add(jeruk);
					panelMenu.add(soda);
					panelMenu.add(joshua);
		
					lbMinum.setForeground(Color.RED);
					lbMinum.setBounds(10,10,100,20);
					lbMinum.setFont(miring);
					teh.setOpaque(false);
					teh.addItemListener(this);
					teh.setBounds(5,45,110,20);
					jeruk.setOpaque(false);
					jeruk.addItemListener(this);
					jeruk.setBounds(5,70,110,20);
					soda.setOpaque(false);
					soda.addItemListener(this);
					soda.setBounds(5,95,110,20);
					joshua.setOpaque(false);
					joshua.addItemListener(this);
					joshua.setBounds(5,120,110,20);
					
					panelMenu.add(lbHMinum);
					panelMenu.add(rp1);
					panelMenu.add(rp2);
					panelMenu.add(rp3);
					panelMenu.add(rp4);
					
					lbHMinum.setForeground(Color.RED);
					lbHMinum.setBounds(140,10,100,20);
					lbHMinum.setFont(miring);
					rp1.setText("Rp "+wr.getHarga(0));
					rp1.setBounds(140,45,110,20);
					rp2.setText("Rp "+wr.getHarga(1));
					rp2.setBounds(140,70,110,20);
					rp3.setText("Rp "+wr.getHarga(2));
					rp3.setBounds(140,95,110,20);
					rp4.setText("Rp "+wr.getHarga(3));
					rp4.setBounds(140,120,110,20);
					
					panelMenu.add(lbJumlah);
					panelMenu.add(tfJml1);
					panelMenu.add(tfJml2);
					panelMenu.add(tfJml3);
					panelMenu.add(tfJml4);
					
					lbJumlah.setForeground(Color.RED);
					lbJumlah.setBounds(270,10,130,20);
					lbJumlah.setFont(miring);
					tfJml1.setEnabled(teh.isSelected());
					tfJml1.setBounds(270,45,60,20);
					tfJml2.setEnabled(jeruk.isSelected());
					tfJml2.setBounds(270,70,60,20);
					tfJml3.setEnabled(soda.isSelected());
					tfJml3.setBounds(270,95,60,20);
					tfJml4.setEnabled(joshua.isSelected());
					tfJml4.setBounds(270,120,60,20);
					
					panelMenu.add(lbHarga);
					panelMenu.add(tfHrg1);
					panelMenu.add(tfHrg2);
					panelMenu.add(tfHrg3);
					panelMenu.add(tfHrg4);
					
					lbHarga.setForeground(Color.RED);
					lbHarga.setBounds(400,10,100,20);
					lbHarga.setFont(miring);
					tfHrg1.setEnabled(false);
					tfHrg1.setBounds(400,45,60,20);
					tfHrg2.setEnabled(false);
					tfHrg2.setBounds(400,70,60,20);
					tfHrg3.setEnabled(false);
					tfHrg3.setBounds(400,95,60,20);
					tfHrg4.setEnabled(false);
					tfHrg4.setBounds(400,120,60,20);
					
			//makanan
				panelPesan.add(panelMenuu);
				panelMenuu.setBackground(new Color(0,150,255));
				panelMenuu.setBounds(550,10,525,245);
				panelMenuu.setLayout(null);
					panelMenuu.add(lbMakan);
					panelMenuu.add(goreng);
					panelMenuu.add(rawon);
					panelMenuu.add(pecel);
					panelMenuu.add(ayam);
					panelMenuu.add(bebek);
					panelMenuu.add(mie);
					
					lbMakan.setForeground(Color.RED);
					lbMakan.setBounds(10,10,100,20);
					lbMakan.setFont(miring);
					
					goreng.setOpaque(false);
					goreng.addItemListener(this);
					goreng.setBounds(5,45,110,20);
					rawon.setOpaque(false);
					rawon.addItemListener(this);
					rawon.setBounds(5,70,110,20);
					pecel.setOpaque(false);
					pecel.addItemListener(this);
					pecel.setBounds(5,95,110,20);
					ayam.setOpaque(false);
					ayam.addItemListener(this);
					ayam.setBounds(5,120,110,20);
					bebek.setOpaque(false);
					bebek.addItemListener(this);
					bebek.setBounds(5,145,110,20);
					mie.setOpaque(false);
					mie.addItemListener(this);
					mie.setBounds(5,170,110,20);
					
					panelMenuu.add(lbHMakan);
					panelMenuu.add(rp5);
					panelMenuu.add(rp6);
					panelMenuu.add(rp7);
					panelMenuu.add(rp8);
					panelMenuu.add(rp9);
					panelMenuu.add(rp10);
					
					lbHMakan.setForeground(Color.RED);
					lbHMakan.setBounds(140,10,100,20);
					lbHMakan.setFont(miring);
					rp5.setText("Rp "+wr.getHarga(4));
					rp5.setBounds(140,45,110,20);
					rp6.setText("Rp "+wr.getHarga(5));
					rp6.setBounds(140,70,110,20);
					rp7.setText("Rp "+wr.getHarga(6));
					rp7.setBounds(140,95,110,20);
					rp8.setText("Rp "+wr.getHarga(7));
					rp8.setBounds(140,120,110,20);
					rp9.setText("Rp "+wr.getHarga(8));
					rp9.setBounds(140,145,110,20);
					rp10.setText("Rp "+wr.getHarga(9));
					rp10.setBounds(140,170,110,20);
				
					panelMenuu.add(lbJumlahh);
					panelMenuu.add(tfJml5);
					panelMenuu.add(tfJml6);
					panelMenuu.add(tfJml7);
					panelMenuu.add(tfJml8);
					panelMenuu.add(tfJml9);
					panelMenuu.add(tfJml10);
					
					lbJumlahh.setForeground(Color.RED);
					lbJumlahh.setBounds(270,10,130,20);
					lbJumlahh.setFont(miring);
					tfJml5.setEnabled(goreng.isSelected());
					tfJml5.setBounds(270,45,60,20);
					tfJml6.setEnabled(rawon.isSelected());
					tfJml6.setBounds(270,70,60,20);
					tfJml7.setEnabled(pecel.isSelected());
					tfJml7.setBounds(270,95,60,20);
					tfJml8.setEnabled(ayam.isSelected());
					tfJml8.setBounds(270,120,60,20);
					tfJml9.setEnabled(bebek.isSelected());
					tfJml9.setBounds(270,145,60,20);
					tfJml10.setEnabled(mie.isSelected());
					tfJml10.setBounds(270,170,60,20);
					
					panelMenuu.add(lbHargaa);
					panelMenuu.add(tfHrg5);
					panelMenuu.add(tfHrg6);
					panelMenuu.add(tfHrg7);
					panelMenuu.add(tfHrg8);
					panelMenuu.add(tfHrg9);
					panelMenuu.add(tfHrg10);
					
					lbHargaa.setForeground(Color.RED);
					lbHargaa.setBounds(400,10,100,20);
					lbHargaa.setFont(miring);
					tfHrg5.setEnabled(false);
					tfHrg5.setBounds(400,45,60,20);
					tfHrg6.setEnabled(false);
					tfHrg6.setBounds(400,70,60,20);
					tfHrg7.setEnabled(false);
					tfHrg7.setBounds(400,95,60,20);
					tfHrg8.setEnabled(false);
					tfHrg8.setBounds(400,120,60,20);
					tfHrg9.setEnabled(false);
					tfHrg9.setBounds(400,145,60,20);
					tfHrg10.setEnabled(false);
					tfHrg10.setBounds(400,170,60,20);
				
				//tombol
					panelPesan.add(panelTombol);
					panelTombol.setBackground(new Color(0,150,255));
					panelTombol.setBounds(10,190,530,65);
					panelTombol.setLayout(null);
					
					panelTombol.add(btPesan);
					btPesan.setEnabled(false);
					btPesan.addActionListener(this);
					btPesan.setBackground(new Color(255,50,50));
					btPesan.setForeground(Color.GREEN);
					btPesan.setBounds(10,15,80,25);
					
					/*panelTombol.add(btLihat);
					btLihat.addActionListener(this);
					btLihat.setBackground(new Color(255,50,50));
					btLihat.setForeground(Color.GREEN);
					btLihat.setBounds(100,15,80,25);*/
					
					panelTombol.add(tombol);
					tombol.addActionListener(this);
					tombol.setBackground(new Color(255,50,50));
					tombol.setForeground(Color.RED);
					tombol.setBounds(100,15,80,25);
					
					panelTombol.add(btHitung);
					btHitung.addActionListener(this);
					btHitung.setBackground(new Color(255,50,50));
					btHitung.setForeground(Color.GREEN);
					btHitung.setBounds(190,15,80,25);
						
					panelTombol.add(lbTotal);
					lbTotal.setFont(new Font("Vernanda", Font.BOLD, 13));
					lbTotal.setForeground(new Color(255,50,50));
					lbTotal.setBounds(300,15,100,25);
					
					panelTombol.add(tfTotal);
					tfTotal.setEnabled(false);
					tfTotal.setBounds(400,15,80,20);

		c.setBackground(Color.WHITE);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(1140,590);
		setLocation(200,50);
		setTitle("Daftar Harga Makanan dan Minuman");
        show();
	}
	
	public void kasir(){
		wr.setJumlah(Integer.parseInt(tfJml1.getText()),0);
		wr.setJumlah(Integer.parseInt(tfJml2.getText()),1);
		wr.setJumlah(Integer.parseInt(tfJml3.getText()),2);
		wr.setJumlah(Integer.parseInt(tfJml4.getText()),3);
		wr.setJumlah(Integer.parseInt(tfJml5.getText()),4);
		wr.setJumlah(Integer.parseInt(tfJml6.getText()),5);
		wr.setJumlah(Integer.parseInt(tfJml7.getText()),6);
		wr.setJumlah(Integer.parseInt(tfJml8.getText()),7);
		wr.setJumlah(Integer.parseInt(tfJml9.getText()),8);
		wr.setJumlah(Integer.parseInt(tfJml10.getText()),9);
		
		tfHrg1.setText(Integer.toString(wr.getSubTotal(0)));
		tfHrg2.setText(Integer.toString(wr.getSubTotal(1)));
		tfHrg3.setText(Integer.toString(wr.getSubTotal(2)));
		tfHrg4.setText(Integer.toString(wr.getSubTotal(3)));
		tfHrg5.setText(Integer.toString(wr.getSubTotal(4)));
		tfHrg6.setText(Integer.toString(wr.getSubTotal(5)));
		tfHrg7.setText(Integer.toString(wr.getSubTotal(6)));
		tfHrg8.setText(Integer.toString(wr.getSubTotal(7)));
		tfHrg9.setText(Integer.toString(wr.getSubTotal(8)));
		tfHrg10.setText(Integer.toString(wr.getSubTotal(9)));
		
		tfTotal.setText(Integer.toString(wr.getTotal()));
	}
	
	public void actionPerformed(ActionEvent e){
		Object cb = e.getSource();
		if(cb.equals(btHitung)){
			kasir();
		}
		if(cb.equals(btPesan)){
			System.exit(0);
		}
		if(cb.equals(btHitung)){
			btPesan.setEnabled(true);
		}
	}
	
	public void itemStateChanged(ItemEvent e){
		Object cb = e.getSource();
		
		if(cb.equals(teh)){
			tfJml1.setEnabled(teh.isSelected());
			if(! teh.isSelected())
				tfJml1.setText("0");
		}
		if(cb.equals(jeruk)){
			tfJml2.setEnabled(jeruk.isSelected());
			if(! jeruk.isSelected())
				tfJml2.setText("0");
		}
		if(cb.equals(soda)){
			tfJml3.setEnabled(soda.isSelected());
			if(! soda.isSelected())
				tfJml3.setText("0");
		}
		if(cb.equals(joshua)){
			tfJml4.setEnabled(joshua.isSelected());
			if(! joshua.isSelected())
				tfJml4.setText("0");
		}
		if(cb.equals(goreng)){
			tfJml5.setEnabled(goreng.isSelected());
			if(! goreng.isSelected())
				tfJml5.setText("0");
		}
		if(cb.equals(rawon)){
			tfJml6.setEnabled(rawon.isSelected());
			if(! rawon.isSelected())
				tfJml6.setText("0");
		}
		if(cb.equals(pecel)){
			tfJml7.setEnabled(pecel.isSelected());
			if(! pecel.isSelected())
				tfJml7.setText("0");
		}
		if(cb.equals(ayam)){
			tfJml8.setEnabled(ayam.isSelected());
			if(! ayam.isSelected())
				tfJml8.setText("0");
		}
		if(cb.equals(bebek)){
			tfJml9.setEnabled(bebek.isSelected());
			if(! bebek.isSelected())
				tfJml9.setText("0");
		}
		if(cb.equals(mie)){
			tfJml10.setEnabled(mie.isSelected());
			if(! mie.isSelected())
				tfJml10.setText("0");
		}
	}
}

 class warung{
	private int[] harga = new int [10];
	private int[] jumlah = new int [10];
	private int[] total = new int [10];
	
	public warung(){
		harga[0] = 2500;
		harga[1] = 3000;
		harga[2] = 7000;
		harga[3] = 7000;
		harga[4] = 5000;
		harga[5] = 7000;
		harga[6] = 7000;
		harga[7] = 10000;
		harga[8] = 10000;
		harga[9] = 5000;
		
		jumlah[0] = 0;
		jumlah[1] = 0;
		jumlah[2] = 0;
		jumlah[3] = 0;
		jumlah[4] = 0;
		jumlah[5] = 0;
		jumlah[6] = 0;
		jumlah[7] = 0;
		jumlah[8] = 0;
		jumlah[9] = 0;

		total[0] = 0;
		total[1] = 0;
		total[2] = 0;
		total[3] = 0;
		total[4] = 0;
		total[5] = 0;
		total[6] = 0;
		total[7] = 0;
		total[8] = 0;
		total[9] = 0;
	}
	
	public void setJumlah(int j, int index){
		jumlah[index]=j;
	}
	
	public int getSubTotal(int index){
		return (harga[index]*jumlah[index]);
	}
	
	public int getHarga(int index){
		return(harga[index]);
	}
	
	public int getTotal(){
		int i,t=0;
		for(i=0;i<=9;i++){
			t=t+(harga[i]*jumlah[i]);
		}
		return(t);
	}
}

class akhir{
	public static void main (String[] args) {
		awal ok = new awal();
		//awall ya = new awall();
	}
}

/*public class awall extends JFrame
{
	private JPanel Jpanelatas = new JPanel();
	
	public awall()
	{
		super("Lihat");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setLocation(200,50);
		setSize(1140,590);
		
		setJpanelatas();
		getContentPane().setLayout(new BorderLayout());
		getContentPane().add(Jpanelatas,BorderLayout.NORTH);
		
		show();
	}
	
	private void setJpanelatas()
	{
		setBackground(Color.GREEN);
	}
}*/